<?php
require_once('conn.php');
require_once('functions.php');
$uid = $_GET['id'];
$dayDel = 60 * 60 * 24;
//$yesterdayTime = mktime(1,0,0,date('m'),date('d')-1,date('Y'));
//$todayTime = mktime(1,1,0,date('m'),date('d'),date('Y'));
//$yesterday = date("Y-m-d h:m:s", $yesterdayTime);
//$today = date("Y-m-d h:m:s", $todayTime);
$yesterday = date("Y-m-d",time() - $dayDel);
$today = date("Y-m-d", time());
$lastThreeDay = date("Y-m-d", time() - $dayDel * 3);
//echo $yesterday."<br>".$today;
?>
<html>
<head>
    <meta charset="UTF-8">
    <title>微有趣</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="./assets/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="./assets/css/income.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
        function changeSize() {
            var propo = $(window).width() / 640;
            $('html').css('font-size', 40 * propo + 'px');
        }
        ;
        changeSize();
        $(window).resize(function () {
            changeSize();
        });
    </script>
</head>
<body>
<div class="wrap">
	<div class="user_id">
		用户ID：<?php echo "{$uid}"?>
	</div>
    <div class="mid">
        <div class="score clearfix">
            <div class="score_left clearfix">
                <p>今日积分收入</p>
                <div class="clearfix">
                    <?php
                    //昨日积分收入
     $yesterdayIncome = $mysql->query("select sum(score) as score from `score_detail` WHERE `day` > '{$today}'  AND `uid` = {$uid} AND `type`=0");
                    $shareincome = $mysql->query("select sum(money) as score from `sharedata` WHERE `day`='{$today}' AND `uid`={$uid} AND `type` != 1");
                    $scoreIncome = $yesterdayIncome[0]['score'] + $shareincome[0]['score'];
                    $gold = $mysql->query("select gold from `user` WHERE `id` = {$uid}");
                    ?>
                    <i class="jt"></i><span class="ji"><?php
                        if ($scoreIncome == 0) {
                            echo 0;
                        } else {
                            echo $scoreIncome;
                        } ?></span>
                </div>
            </div>
            <div class="score_right clearfix">
                <p>总收入（金币）</p>
                <span class="jinbi"><?php
                    if ($gold[0]['gold'] == null) {
                        echo 0;
                    } else {
                        echo $gold[0]['gold'];
                    }
                    ?></span>
            </div>
        </div>
        <div class="prompt">
            <p>积分转金币汇率为：<span>1000</span>积分 = <span>1</span>金币=1元</p>
        </div>
    </div>
    <div class="bot">
        <div class="nav clearfix">
            <div class="left clearfix">
                收入明细
            </div>
            <div class="center clearfix">
                分享明细
            </div>
            <div class="right clearfix">
                支出明细
            </div>
        </div>
        <div class="con">
            <!--					收入明细-->
            <ul id="list1">
                <?php
                $incomeDetailSql = "select * from `score_detail` where `day` >= '{$lastThreeDay}' AND `uid` = {$uid}  order by `day` desc";
                $incomeDetailRow = $mysql->query($incomeDetailSql);
                ?>
                <?php
                foreach ($incomeDetailRow as $value) {
                    if($value['type'] == 1){
                        $content = "金币";
                    }else if($value['type'] == 0){
                        $content = "积分";
                    }
                    ?>
                    <li>
                        <p class="qd"><?= $value['content'] ?><span class="t_right""><b>+</b><?= $value['score'] ?><b
                                    class="type"><?= $content?></b></span></p>

                        <p class="li_ms"><?= $value['content'] ?>
                            奖励<span><?= $value['day'] ?></span></p>
                    </li>
                <?php } ?>
            </ul>
            
            <!--					分享明细-->
            <ul style="display: none;" id="list3">
                <?php
                $shareDetailSql = "select * from `sharedata` where `day` >= '{$lastThreeDay}' AND `uid` = {$uid} AND type!=1  order by `day` desc,time desc";
                $shareDetailRow = $mysql->query($shareDetailSql);
                ?>
                <?php
                foreach ($shareDetailRow as $value) {
                   
                    ?>
                    <li>
                        <p class="qd"><?php if($value['type'] == 0){echo '分享文章';}else if($value['type'] == 2){echo '好友分享贡献';}?><span class="t_right"><b>+</b><?= $value['money'] ?><b
                                    class="type">积分</b></span></p>

                        <p class="li_ms"><?php if($value['type'] == 0){echo '分享文章';}else if($value['type'] == 2){echo '好友分享';}?>
                            奖励<span><?= $value['day'].' '.$value['time'] ?></span></p>
                    </li>
                <?php } ?>
            </ul>


            <!--					支出明细-->
            <ul style="display: none;" id="list2">
                <?php
                $expenditureSql = "select * from `send` where `day` >= '{$lastThreeDay}' AND `uid` = {$uid} ORDER BY `day` DESC";
                $expenditureDetailRow = $mysql->query($expenditureSql);
                //                echo "<pre>";
                //                print_r($expenditureDetailRow);
                ?>
                <?php
                foreach ($expenditureDetailRow as $value) {
                    ?>
                    <li>
                        <p class="qd">积分赠送<span class="t_right"><b>-</b><?= $value['score'] ?><b
                                    class="type">积分</b></span></p>

                        <p class="li_ms"><?= $value['content'] ?><span><?= $value['day'] ?></span></p>
                    </li>
                <?php } ?>
            </ul>
            <div class="end">
                系统只保留最近三天的收入支出明细
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(".t_right").css("color", "#3cb715");
        $(".left").css("border-bottom", "2px solid #3cb715");
        $(".left").css("color", "#3cb715");
        $(".left").click(function () {
            $(this).css("border-bottom", "2px solid #3cb715").siblings().css("border", "none");
            $(this).css("color", "#3cb715").siblings().css("color", "#000000");
            $(".t_right").css("color", "#3cb715");
            $("#list1").show();
            $("#list2").hide();
            $("#list3").hide();

        });
        $(".right").click(function () {
            $(this).css("color", "#3cb715").siblings().css("color", "#000000");
            $(this).css("border-bottom", "2px solid #3cb715").siblings().css("border", "none");
            $(".t_right").css("color", "red");
            $("#list2").show();
            $("#list1").hide();
            $("#list3").hide();
        });
        $(".center").click(function () {
            $(this).css("color", "#3cb715").siblings().css("color", "#000000");
            $(this).css("border-bottom", "2px solid #3cb715").siblings().css("border", "none");
            $(".t_right").css("color", "#3cb715");
            $("#list3").show();
            $("#list1").hide();
            $("#list2").hide();
        });
    })
</script>
</body>
</html>
